/// 某个医院的租金明细列表

var app = getApp()
//常量数据配置
var ConstantData = require('../../../../common/constant_data.js')
//获取应用实例  
Page({
  
  data: {
    
    leseDetail:'',
    hospitalName:'',
    pageSize: 20,
    pageNum: 1,
    orderList: [],
    loading:true,
    loadingComplete:false,
    state:null
  },


  
  onLoad: function (options) {
    var that = this;
    console.log("--------options->",options);
    var mecId = options.mecId;
    var hospitalName = options.hospitalName;
    var date = options.date;
    var isNoReal = options.isNoReal;
    var state = options.state;
    that.data.isNoReal = isNoReal;
    
    var dateStr = date.substr(0,4) + "-" + date.substr(4,2) +"-"+date.substr(6,2);
    var startDate = dateStr +" 00:00:00";
    var endDate = dateStr + " 23:59:59";
    
    if (date == '总') {
      var sDate = options.startDate;
      var sYear = sDate.substr(0, 4);
      var sMonth = sDate.substr(5, 2);
      startDate = sYear + "-" + sMonth + "-01 00:00:00";
      if(sMonth == 12) {
        sYear++;
        sMonth=1;
      }else {
        sMonth++;
      }
      endDate = sYear + "-" + sMonth +"-01 00:00:00";
    }

    this.setData({
      mecId: mecId,
      hospitalName: hospitalName,
      startDate: startDate,
      endDate: endDate,
      state: state
    });

    that.init(startDate,endDate);
  },
 
 
  
  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom: function () {
   
    var that = this;
    if (that.data.loading && !that.data.loadingComplete) {
      that.setData({
        loading: false,
        pageNum: that.data.pageNum + 1,  //每次触发上拉事件，把searchPageNum+1  
      });
      
      that.init(that.data.startDate, that.data.endDate);
    }
  },
  

  init: function (startDate, endDate) {

    var that = this;
    console.log('===========>',that.data)
    if (that.data.state==0) {
      app.executeRequest(function (header) {
        wx.request({
          url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_statistic/lease_pay/detail',
          header: header,
          data: {
            startDate: startDate,
            endDate: endDate,
            mecId: that.data.mecId,
            startNum:(that.data.pageNum - 1) * that.data.pageSize,
            pageSize:that.data.pageSize,
            isNoReal:that.data.isNoReal
          },
          success: function (res) {
            console.log("11111---->", res);
            if (res.data.length == 0) {
              that.setData({
                loadingComplete: true
              });
              return;
            }
            var list = that.data.orderList;
            for (var i = 0; i < res.data.length; i++) {            
              res.data[i].uur_order_code = res.data[i].uur_order_code.substr(8);
              if (res.data[i].uur_pay_stat == 0) {
                res.data[i].uur_consume_cash = '未归还';
              }else if(res.data[i].uur_pay_stat == 1) {
                res.data[i].uur_consume_cash = '￥'+res.data[i].uur_consume_price +'未支付';
              } else if (res.data[i].uur_pay_stat == 2){
                res.data[i].uur_consume_cash = '￥' + res.data[i].uur_consume_cash;
              }else {              
              }
              list.push(res.data[i])
            }
            that.setData({
              orderList: list,
              loading: true
            })
          }
        })
      }); 
    } else if(that.data.state==1) {
      app.executeRequest(function (header) {
        wx.request({
          url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_statistic/lease_pay/detailReturn',
          header: header,
          data: {
            startDate: startDate,
            endDate: endDate,
            mecId: that.data.mecId,
            startNum:(that.data.pageNum - 1) * that.data.pageSize,
            pageSize:that.data.pageSize,
            isNoReal:that.data.isNoReal
          },
          success: function (res) {
            console.log("11111---->", res);
            if (res.data.length == 0) {
              that.setData({
                loadingComplete: true
              });
              return;
            }
            var list = that.data.orderList;
            for (var i = 0; i < res.data.length; i++) {            
              res.data[i].uur_order_code = res.data[i].uur_order_code.substr(8);
              if (res.data[i].uur_pay_stat == 0) {
                res.data[i].uur_consume_cash = '未归还';
              }else if(res.data[i].uur_pay_stat == 1) {
                res.data[i].uur_consume_cash = '￥'+res.data[i].uur_consume_price +'未支付';
              } else if (res.data[i].uur_pay_stat == 2){
                res.data[i].uur_consume_cash = '￥' + res.data[i].uur_consume_cash;
              }else {              
              }
              list.push(res.data[i])
            }
            that.setData({
              orderList: list,
              loading: true
            })
          }
        })
      }); 
    }
     
  
  }

})  


